package app.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Environment;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ListAdapter;
import android.widget.ListView;
import app.http.HttpHelper;
import app.log.APPLog;
import app.struct.AppKeyConstants;
import app.struct.DataHashMap;
import app.widget.MessageDialog;
import app.widget.dialog.HomePageExitDialog;

import com.longevityassistant.activity.R;

/**
 * @author CUNGUANTONG
 * @date 2011-12-14
 * @version
 * @description 工具处理类convertStreamToString
 */
public class CommonUtils {

	private static final String TAG = CommonUtils.class.getSimpleName();

	private static AlertDialog alertDialog = null;

	public static final int MSG_SHOW_ALERTDIALOG = 1;

	private static Context ct = null;
	
	private static MessageDialog mMessageDialog;
	
	private static OnAlertDialogButtonClickListener leftListener = null;
	
	private static OnAlertDialogButtonClickListener rightListener = null;
	
	private static android.content.DialogInterface.OnCancelListener cancelListener = null;
	
	private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
	
	private static List<Activity> activityList = new ArrayList<Activity>(); 
	
	private static Calendar now = Calendar.getInstance();
	
	private static Calendar lastWeek;
	
	private static Calendar lastMonth;
	
	private static Calendar lastSixMonth ;
	/**
	 * 转出
	 */
	public static final String IP_FLAG_REC= "0";
	/**
	 * 转入
	 */
	public static final String IP_FLAG_PAY= "1";
	
	public static final String SHARED_CONFIG_FILE_NAME = "shared_config";

	/**
	 * 判断网络是否畅通
	 * 
	 * @param context
	 * @return
	 */
	public static boolean isNetworkAvailable(Context context) 
	{
		ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		if (connectivity == null) {
			return false;
		} 
		else 
		{
			NetworkInfo[] info = connectivity.getAllNetworkInfo();
			if (info != null) 
			{
				for (int i = 0; i < info.length; i++) 
				{
					if (info[i].getState() == NetworkInfo.State.CONNECTED) {
						return true;
					}
				}
			}
		}
		return false;
	}
	
	/**
	 * [带一个按钮的提示框,并支持html格式显示]<BR>
	 * @param context 上下文
	 * @param tipMsg 提示信息
	 */
	public static void showAlertDialog(Context context, String tipMsg , boolean isHtml) {
		showAlertDialog(context, null, null, null, tipMsg , isHtml);
	}
	
	/**
	 * [带一个按钮的提示框,并支持html格式显示]<BR>
	 * @param context 上下文
	 * @param tipMsg 提示信息
	 */
	public static void showAlertDialog(Context context, String tipMsg , boolean isHtml , int gravity) {
		showAlertDialog(context, null, null, null, tipMsg , isHtml , gravity);
	}
	
	/**
	 * [带一个按钮的提示框]<BR>
	 * @param context 上下文
	 * @param tipMsg 提示信息
	 */
	public static void showAlertDialog(Context context, String tipMsg) {
		showAlertDialog(context, null, null, null, tipMsg, false);
	}

	/**
	 * [带一个按钮的提示框]<BR>
	 * @param context 上下文
	 * @param tipMsg 提示信息
	 * @param btnMsg 按钮名称
	 */
	public static void showAlertDialog(Context context, String tipMsg, String btnMsg) {
		showAlertDialog(context, null, btnMsg, null, tipMsg, false);
	}
	
	public static void showAlertDialog(Context context, String tipMsg, String btnMsg, int gravity) {
		showAlertDialog(context, null, btnMsg, null, tipMsg, false, gravity);
	}
	
	
	/**
	 * [带两个按钮的提示框]<BR>
	 * @param context 上下文
	 * @param tipMsg 提示信息
	 * @param btnMsg1 按钮1名称
	 * @param btnMsg2 按钮2名称
	 */
	public static void showAlertDialog(Context context, String tipMsg, String btnMsg1, String btnMsg2) {
		showAlertDialog(context, null, btnMsg1, btnMsg2, tipMsg, false);
	}
		
	
	
	 /**
	 * [一句话功能简述]<BR>
	 * [功能详细描述]
	 * @param context
	 * @param titleMsg
	 * @param btnMsg1
	 * @param btnMsg2
	 * @param tipMsg
	 */
	public static void showAlertDialog(Context context, String titleMsg, String btnMsg1, String btnMsg2, String tipMsg) 
	{
		 showAlertDialog(context, titleMsg, btnMsg1, btnMsg2, tipMsg , false);
	}
	
	  public static void showAlertDialog(Context context, String titleMsg,
	            String btnMsg1, String btnMsg2, String tipMsg , boolean isHtml) {
	      showAlertDialog(context, titleMsg, btnMsg1, btnMsg2, tipMsg, isHtml, Gravity.CENTER);
	  }
	 
	/**
     * 统一弹出提示对话框
     * [功能详细描述]
     * @param context 上下文
     * @param titleMsg 标题
     * @param btnMsg1 按钮1名称
     * @param btnMsg2 按钮2名称
     * @param tipMsg 提示消息
     */
    public static void showAlertDialog(Context context, String titleMsg,
            String btnMsg1, String btnMsg2, String tipMsg , boolean isHtml, int gravity) {

		if (mMessageDialog != null && mMessageDialog.isShowing()
				&& ct == context && context != null) {
			APPLog.e(TAG, "alertDialog.isShowing()");
			return;
		}
        
        if(((Activity) context).isFinishing())
        {
            return;
        }
        
        mMessageDialog = new MessageDialog(context);
        mMessageDialog.setTitle(R.string.dialog_title_tip_defalut);
        mMessageDialog.setTextViewGravity(gravity);
        
        if (!Tools.isEmpty(titleMsg)) {
            mMessageDialog .setTitle(titleMsg);
        }
        mMessageDialog.setMessage(tipMsg, isHtml);
        
        if (!Tools.isEmpty(btnMsg1)) {
            mMessageDialog.setBtn1Text(btnMsg1);    
        }
        
        mMessageDialog.setBtn1ClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                if(leftListener!=null) {
                    leftListener.onClick();
                }
                leftListener = null;
                rightListener = null;
            }
        });
        
        if (Tools.isEmpty(btnMsg2)) {
            mMessageDialog.setBtn2Visible(false);
        }  else {
            mMessageDialog.setBtn2Visible(true);
            mMessageDialog.setBtn2Text(btnMsg2);
			mMessageDialog.setBtn2ClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					if (rightListener != null) {
						rightListener.onClick();
					}
					rightListener = null;
					leftListener = null;
				}
			});
        }
        

		mMessageDialog.setOnCancelListener(new OnCancelListener() {

			@Override
			public void onCancel(DialogInterface dialog) {
				// TODO Auto-generated method stub
				if (cancelListener != null) {
					cancelListener.onCancel(dialog);
				}
				cancelListener = null;
				leftListener = null;
				rightListener = null;

			}
		});
        
        // 对话框展示出来
        mMessageDialog.show();
        ct = context;
    }
    
    
	
	public static void setOnAlertDialogButtonClickListener(OnAlertDialogButtonClickListener onAlertDialogButtonClickListener)
	{
		leftListener = onAlertDialogButtonClickListener;
	}

	public static void setOnAlertDialogLeftButtonClickListener(OnAlertDialogButtonClickListener onAlertDialogButtonClickListener)
	{
		leftListener = onAlertDialogButtonClickListener;
	}
	
	public static void setOnAlertDialogRightButtonClickListener(OnAlertDialogButtonClickListener onAlertDialogButtonClickListener)
	{
		rightListener = onAlertDialogButtonClickListener;
	}
	
	public static void setOnCancelListener(DialogInterface.OnCancelListener listener) {
		cancelListener = listener;
	}
	
	public interface OnAlertDialogButtonClickListener{
		public void onClick();
	}
	
	/**
	 * 提示是否退出程序
	 * 
	 * @param activity
	 * @param msgContent
	 */
	public static void showTipDialog(Context mContext, String msgContent)
	{
		showTipDialog(mContext, msgContent, null);
	    
//		HomePageExitDialog messageDialog = new HomePageExitDialog(mContext,msgContent);
//		messageDialog.show();
	    /*messageDialog.setTitle(R.string.exit);
	    messageDialog.setMessage(msgContent);
	    messageDialog.setBtn1Text(R.string.sure);
	    messageDialog.setBtn1ClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                //退出本次应用的程序
                CommonUtils.finishProgram();  
            }
        });
	    messageDialog.show();*/
	    
	    
//		LayoutInflater mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//		View view = (View)mInflater.inflate(R.layout.tip_dialog2, null);
//		
//		alertDialog = new AlertDialog.Builder(mContext).create();
//		alertDialog.show();
//		alertDialog.getWindow().setLayout(android.view.WindowManager.LayoutParams.WRAP_CONTENT,
//				android.view.WindowManager.LayoutParams.WRAP_CONTENT);
//		alertDialog.getWindow().setContentView(view);
//		
//		TextView tipText = (TextView)view.findViewById(R.id.tip_text);
//		tipText.setText(msgContent);
//		
//		Button okButton = (Button)view.findViewById(R.id.tip_button);
//		okButton.setText(R.string.sure);
//		Button cancelButton = (Button)view.findViewById(R.id.tip_button2);
//		
//		okButton.setOnClickListener(new View.OnClickListener() {			
//			@Override
//			public void onClick(View v) {
//				//退出本次应用的程序
//				CommonUtils.finishProgram();   
//			}
//		});
//		cancelButton.setOnClickListener(new View.OnClickListener() {			
//			@Override
//			public void onClick(View v) {
//				alertDialog.cancel();
//			}
//		});
	}
	

	/**
	 * 提示是否退出程序
	 * 
	 * @param activity
	 * @param msgContent
	 */
	public static void showTipDialog(Context mContext, String msgContent, HomePageExitDialog.OnHomePageTipShowLisetner lisetner)
	{
	    
		HomePageExitDialog messageDialog = new HomePageExitDialog(mContext,msgContent, lisetner);
		messageDialog.show();
	}


	
	
	


	public static String getAccType(String code){
		if("8101".equals(code)){
			return "活期结算";
		}
		else if("8102".equals(code)){
			return "活期储蓄";
		}
		else if("8103".equals(code)){
			return "活期资本";
		}
		else if("8104".equals(code)){
			return "活期储蓄类";
		}
		else if("8301".equals(code)){
			return "活期支票";
		}
		else if("8701".equals(code)){
			return "活期预付卡";
		}
		else if("8801".equals(code)){
			return "活期委托";
		}
		else if("8901".equals(code)){
			return "活期结构";
		}
		else if("9201".equals(code)){
			return "零整";
		}
		else if("9101".equals(code)){
			return "整存整取";
		}
		else if("9102".equals(code)){
			return "大额整存整取";
		}
		else if("9103".equals(code)){
			return "整存整取资本";
		}
		else if("9601".equals(code)){
			return "通知存款";
		}
		else if("9603".equals(code)){
			return "通知存款资本";
		}
		else if("9301".equals(code)){
			return "存本取息";
		}
		else if("8201".equals(code)){
			return "定活两便";
		}
		return "";
	}
	
	

	/**
	 * 根据服务器返回的帐户状态码获得帐户状态
	 * 
	 * @param accStatus
	 * @return
	 */
	public static String getAccStatus(String accStatus) {
		String str = "";
		if ("0000000000000000".equals(accStatus)) {
			str = "正常";
		} else if ("1000000000000000".equals(accStatus)) {
			str = "销户";
		} else if ("0100000000000000".equals(accStatus)) {
			str = "转收益";
		} else if ("0010000000000000".equals(accStatus)) {
			str = "睡眠户";
		} else if ("0001000000000000".equals(accStatus)) {
			str = "不动户";
		} else if ("0000100000000000".equals(accStatus)) {
			str = "只收不付冻结";
		} else if ("0000010000000000".equals(accStatus)) {
			str = "不收不付冻结";
		} else if ("0000001000000000".equals(accStatus)) {
			str = "止付";
		} else if ("0000000100000000".equals(accStatus)) {
			str = "抵押";
		} else if ("0000000010000000".equals(accStatus)) {
			str = "不结息";
		}

		return str;
	}

	/**
	 * @param endOper
	 * @return
	 */
	public static String getEndOper(String endOper) {
		String str = "";
		if ("".equals(endOper)) {
			str = "无到期约定";
		} else {
			int num = Integer.parseInt(endOper);
			switch (num) {
			case 0:
				str = "不转存";
				break;
			case 1:
				str = "本息续存";
				break;
			case 2:
				str = "本金续存，利息转活期";
				break;
			case 3:
				str = "本息转活期";
				break;

			default:
				break;
			}
		}
		return str;
	}

	
	public static String getStockActiveStatus(String status){
		if("0".equals(status)){
			return "已激活";
		}
		else if("1".equals(status)){
			return "已激活";
		}
		else if("2".equals(status)){
			return "已激活";
		}
		else if("8".equals(status)){
			return "未激活";
		}
		else if("9".equals(status)){
			return "未激活";
		}
		return "";
	}
	
	
	public static String getCurrType(String currCode){
		if("156".equals(currCode)){
			return "人民币";
		}
		else if("250".equals(currCode)){
			return "马克";
		}
		else if("256".equals(currCode)){
			return "法郎";
		}
		else if("344".equals(currCode)){
			return "港元";
		}
		else if("392".equals(currCode)){
			return "日元";
		}
		else if("826".equals(currCode)){
			return "英镑";
		}
		else if("840".equals(currCode)){
			return "美元";
		}
		else if("954".equals(currCode)){
			return "欧元";
		}
		return "";
	}
	
	/**
	 * 
	 *      * 0:正在核对
     * 1:核对失败
     * 2:批次正在处理
     * 3:批次受理完成
     * 4:批次完成处理
     * 5:预约待处理
     * 6:预约处理完成
     * 7:撤销
	 */
	
	/**
	 * 得到当前币种
	 * @param currType
	 * @return
	 */
	public static String getBatchTransferStatus(String status) {
        if("0".equals(status)){
        	return "正在核对";
        }
        else if("1".equals(status)){
        	return "核对失败";
        }
        else if("2".equals(status)){
        	return "批次正在处理";
        }
        else if("3".equals(status)){
        	return "批次受理完成";
        }
        else if("4".equals(status)){
        	return "批次完成处理";
        }
        else if("5".equals(status)){
        	return "预约待处理";
        }
        else if("6".equals(status)){
        	return "预约处理完成";
        }
        else if("7".equals(status)){
        	return "撤销";
        }
        return "";
	}
	
	public static String getBatchTransferOrderType(String orderType){
		if(orderType!=null){
			if("00".equals(orderType)){
				return "行内活期转帐";
			}
			else if("01".equals(orderType)){
				return "活期转定期";
			}
			else if("07".equals(orderType)){
				return "跨行转帐";
			}
			else if("14".equals(orderType)){
				return "信用卡还款";
			}
		}
		
		return "";
	}
	
	public static String getTransferOrderStatus(String status){
		if(status!=null){
			if("0".equals(status.trim())){
				return "成功";
			}
			else if("1".equals(status.trim())){
				return "失败";
			}
			else if("2".equals(status.trim())){
				return "已受理";
			}
			else if("3".equals(status.trim())){
				return "已发送待清算";
			}
			else if("4".equals(status.trim())){
				return "落地待处理";
			}
			else if("5".equals(status.trim())){
				return "落地待审核";
			}
			else if("6".equals(status.trim())){
				return "退票";
			}
			
		}
		return "";
	}
	
	public static String getTransferAppointStatus(String bookingStatus){
		if("0".equals(bookingStatus)){
			return "有效";  
		}
		else if("1".equals(bookingStatus)){
			return "撤销";
		}
		else if("2".equals(bookingStatus)){
			return "完成";
		}
		else if("3".equals(bookingStatus)){
			return "预约处理中";
		}
		return "";
	}
	
	public static String getTransChannel(String channel){
		if("0".equals(channel)){
			return "柜台交易";
		}
		else if("1".equals(channel)){
			return "网上银行";
		}
		else if("2".equals(channel)){
			return "自助查询终端";
		}
		else if("3".equals(channel)){
			return "电话银行";
		}
		else if("4".equals(channel)){
			return "ATM";
		}
		else if("5".equals(channel)){
			return "TA发起";
		}
		else if("6".equals(channel)){
			return "低柜";
		}
		else if("9".equals(channel)){
			return "基金管理台";
		}
		return "";
	}
	
	public static String getTransferOrderType(String orderType,String orderFlag){
		try {
			int orderTypeInt = Integer.parseInt(orderType);
			int orderFlagInt = 0;
			try {
				orderFlagInt = Integer.parseInt(orderFlag);
			}catch (NumberFormatException e) {
				// TODO: handle exception
			}
			String orderFlagStr = "";
			String orderTypeStr = "";
			if(orderFlagInt==2){
				orderFlagStr ="预约";
			}
			else if(orderFlagInt==3){
				orderFlagStr ="周期";
			}
			
			switch(orderTypeInt){
		         case 0:
		        	 orderTypeStr = "同行"+orderFlagStr+"转账";
		             break;
		         case 5:
		        	 orderTypeStr = "跨行实时转账";
		             break;
		         case 6:
		        	 orderTypeStr = "跨行实时收款";
		             break;
		         case 7:
		        	 orderTypeStr = "跨行"+orderFlagStr+"转账";
		             break;
		         case 9:
		        	 orderTypeStr = "同行"+orderFlagStr+"转账";
		             break;
		         case 14:
		        	 orderTypeStr = "平安信用卡还款";
		             break;
		         case 18:
		        	 orderTypeStr = "平安信用卡还款";
		             break;
		         default:
		        	 orderTypeStr = "";
			}

			return orderTypeStr;
		} catch (NumberFormatException e) {
			// TODO: handle exception
		}
		return "";
	}
	
	public static String getTransferSerialType(String serialType){
		if(serialType!=null){
			if("00".equals(serialType)){
				return "同行转帐";
			}
			else if("01".equals(serialType)){
				return "活转定";
			}
			else if("02".equals(serialType)){
				return "定转活";
			}
			else if("07".equals(serialType)){
				return "跨行转账";
			}
			else if("14".equals(serialType)){
				return "活期转信用卡";
			}
			else if("15".equals(serialType)){
				return "同行预约转账";
			}		
			else if("16".equals(serialType)){
				return "跨行预约转账";
			}
			else if("17".equals(serialType)){
				return "预约活转定";
			}
			else if("18".equals(serialType)){
				return "未知";
			}
			else if("20".equals(serialType)){
				return "行内异名转入";
			}
			else if("21".equals(serialType)){
				return "实时跨行转账";
			}
			else if("22".equals(serialType)){
				return "跨行时候收款";
			}
			else if("1".equals(serialType)){
				return "批量转账";
			}
			else if("2".equals(serialType)){
				return "批量预约转账";
			}
		}
		return "";
	}
	
	public static String getTransferType(String type){
		if("01".equals(type)){
			return "同城跨行";
		}
		else if("02".equals(type)){
			return "异地跨行";
		}
		else if("03".equals(type)){
			return "同城同行";
		}
		else if("04".equals(type)){
			return "异地同行";
		}
		return "";
	}
	
	public static String getTransferAppointSerialType(String serialType){
		if("01".equals(serialType)){
			return "同城跨行";
		}
		else if("02".equals(serialType)){
			return "异地跨行";
		}
		else if("03".equals(serialType)){
			return "同城同行";
		}
		else if("04".equals(serialType)){
			return "异地同行";
		}
		else if("05".equals(serialType)){
			return "同行活期转定期";
		}
		return "";
	}
	
	public static String getTransferIpFlag(String ipFlag){
		if("1".equals(ipFlag)){
			return "转入";
		}
		else if("2".equals(ipFlag)){
			return "转出";
		}
		return "";
	}
	
	public static String getCircleTransferIpFlag(String ipFlag){
		if("0".equals(ipFlag)){
			return "转入";
		}
		else if("1".equals(ipFlag)){
			return "转出";
		}
		return "";
	}
	
	/**
	 * [指令状态]<BR>
	 * @param status
	 * @return
	 */
	public static String getTransferAppointSerialStatus(String status){
		if("0".equals(status)){
			return "有效";
		}
		else if("1".equals(status)){
			return "撤销";
		}
		else if("2".equals(status)){
			return "完成";
		}
		else if("3".equals(status)){
			return "预约处理中";
		}
		
		return "";
	}
	
	public static String getTransferAppointPeriodType(String periodType){
		if("0".equals(periodType)){
			return "单次转账";
		}
		else if("1".equals(periodType)){
			return "周期转账";
		}
		return "";
	}
	
	public static String getTransferAppointSettlementMode(String settlementMode){
		if("1".equals(settlementMode)){
			return "留存金额";
		}
		else if("2".equals(settlementMode)){
			return "固定金额";
		}
		return "";
	}
	
	public static String getTransferAppointTime(String time){
		if("00".equals(time)){
			return "上午";
		}
		else if("01".equals(time)){
			return "下午";
		}
		
		return "";
	}
	
	
	/**0
	 * [初始化所有城市]<BR>
	 * [功能详细描述]
	 * @param context context
	 * @return
	 */
	public static List<Map<String, Object>> initProvinceList(Context context)
	{
		List<Map<String, Object>> mList = new ArrayList<Map<String, Object>>();
		String[] provinArray = context.getResources().getStringArray(R.array.province);
		String[] tempArray = null;
		Map<String, Object> map = null;
		
		for(int i=0;i<provinArray.length;i++)
		{
			tempArray = provinArray[i].split("#");
			map = new HashMap<String, Object>();
			map.put(AppKeyConstants.PROVINCE_CODE, tempArray[0]);
			map.put(AppKeyConstants.PROVINCE_NAME, tempArray[1]);
			mList.add(map);
		}
		
		return mList;
	}

	/**
	 * 获取收支标志
	 * [一句话功能简述]<BR>
	 * [功能详细描述]
	 * @param ipFlag
	 * @return
	 */
	public static String getIpFlag(int ipFlag) 
	{
	    String str = null;
	    switch (ipFlag) {
	        case 0:
	            str = "转入";
	            break;
	        case 1:
	            str = "转出";
	            break;
	        case 2:
	            str = "转入";
	            break;
		default:
			break;
	        
	    }
	    return str;
	}
	
	
	
	

	/**
	 * 获取银行卡的别名,当别名为空时,返回未命名
	 * @param alias
	 * @return
	 */
	public static String getAlias(String alias) {
	    String str;
	    if (Tools.isEmpty(alias) || "---".equals(alias)) {
	        str = "未命名";
	    } else {
	        str = alias;
	    }
	    
	    return str;
	}
	
	/**
	 * [获取转账类型]<BR>
	 * @param orderType 指令类型
	 * @param orderFlag 指令标记
	 * @return 转账指令类型
	 */
	public static String getOrderTypeTip(String orderType, String orderFlag) {
		
		if (orderType.equals("01")) {
			if (orderFlag.equals("1")) {
				return "活期转定期";
			} else {
				return "活期预约转账";
			}
		} else if (orderType.equals("02")) {
			return "定期转活期";
		}
		return "";
	}

	/**
	 * [模糊搜索动态数组]<BR>
	 * [功能详细描述]
	 * @param list 页面得到的数组
	 * @param key  要匹配字段的key
	 * @param like 模糊字符
	 * @return
	 */
	public static List<Map<String, Object>> qryLikeList(List<Map<String, Object>> list, String key, String like)
	{
		if(Tools.isEmpty(like)) {
			return list;
		}
			
		List<Map<String, Object>> mlist = new ArrayList<Map<String,Object>>();
		if(list != null)
		{
			String value = "";
			Map<String, Object> map = null;
			
			for(int i=0;i<list.size();i++)
			{
				map = list.get(i);
				if(map != null)
				{
					value = map.get(key).toString();
					if(value.indexOf(like) > -1){
						mlist.add(map);
					}
				}
			}
		}
		return mlist;
	}
	
	/**
	 * 
	 */
	public static void reLogin()
	{
//		HttpConnector.removeAllReqList();
		DataCache.clearAll();
		CookieUtils.clearAll();
		finishProgram();
		rightListener = null;
		leftListener = null;
	}
	
	
	/**
	 * @param is
	 * @return
	 */
	public static String convertStreamToString(InputStream is) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(is));
		StringBuilder sb = new StringBuilder();

		String line = null;
		try {
			while ((line = reader.readLine()) != null) {
				sb.append(line + "\n");
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				is.close();
				reader.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			String s = sb.toString().replaceAll("\n", "");
			APPLog.e("HttpUtil","convertStreamToString->"+s);
			return s;
		}
	}
	
	
	/**
	 * 计算ListView高度并写定高度
	 * 
	 * @param listView 仅对于Listitem布局为LinearLayout的有效
	 */
	public static void setListViewHeightBasedOnChildren(ListView listView) {
		ListAdapter listAdapter = listView.getAdapter();
		if (listAdapter == null) {
			return;
		}

		int totalHeight = 0;
		for (int i = 0; i < listAdapter.getCount(); i++) {
			View listItem = listAdapter.getView(i, null, listView);
			listItem.measure(0, 0);
			totalHeight += listItem.getMeasuredHeight();
		}

		int height = totalHeight
				+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));
		LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, height);
		listView.setLayoutParams(params);
	}

	
	
	
	
	/**
	 * 返回今天的日期，格式20111109
	 * @return
	 */
	public static String getToday(){
		return dateFormat.format(now.getTime());
	}
	
	public static String getToday(String format){
		if (format != null) {
			SimpleDateFormat dateFormat = new SimpleDateFormat(format);
			return dateFormat.format(now.getTime());
		} else {
			return now.getTime().getTime() + "";
		}
	}
	
	/**
	 * 返回30天前的日期
	 * @return
	 */
	public static String getPreMonth(){
		Calendar preMonth = Calendar.getInstance();
		return getPreMonth(preMonth);
	}
	
	public static String getPreMonth(Calendar calendar) {
		calendar.add(Calendar.MONTH, -1);
		return dateFormat.format(calendar.getTime());
	}
	
	/**
	 * 返回6个月前的日期
	 * @return
	 */
	public static String getLastSixMonth(){
		lastSixMonth = Calendar.getInstance();
		lastSixMonth.add(Calendar.DAY_OF_YEAR, -180);
		return dateFormat.format(lastSixMonth.getTime());
	}
	
	/**
	 * 得到下一周
	 * @return
	 */
	public static String getLastWeek(){
		lastWeek = Calendar.getInstance();
		lastWeek.add(Calendar.DAY_OF_YEAR, -7);
		return dateFormat.format(lastWeek.getTime());
	}
	
	/**
	 * 得到下一个月
	 * @return
	 */
	public static String getLastMonth(){
		lastMonth = Calendar.getInstance();
		lastMonth.add(Calendar.DAY_OF_YEAR, -7);
		return dateFormat.format(lastMonth.getTime());
	}

	/**
	 * 得到下一年的当天日期
	 * 优先获取服务器时间
	 * @return
	 */
	public static String getNextYear(){
		String nextYear = "";
		Calendar tempdate = getCurrentTimeByCalendar();
		tempdate.add(Calendar.YEAR, 1);
		nextYear = Tools.format(tempdate, "yyyyMMdd");
		tempdate.add(Calendar.YEAR, -1);
		return nextYear;
	}
	
	/**
	 * 得到上一年的当天日期
	 * 优先获取服务器时间
	 * @return
	 */
	public static String getBeforYear(){
		String lastYear = "";
		Calendar tempdate = getCurrentTimeByCalendar();
		tempdate.add(Calendar.YEAR, -1);
		lastYear = Tools.format(tempdate, "yyyyMMdd");
		tempdate.add(Calendar.YEAR, 1);
		return lastYear;
	}
	
	/**
     * 得到系统级别的缓存对象
     * @param context
     * @return
     */
    public static SharedPreferences getSysShare(Context context, String mapKey){
        return context.getSharedPreferences(mapKey, Context.MODE_PRIVATE);
    }
    
    /**
     * 添加系统缓存信息
     * 
     * [一句话功能简述]<BR>
     * [功能详细描述]
     * @param context
     * @param mapKey
     * @param key
     * @param value
     */
    public static void saveSysMap(Context context ,String mapKey, String key , String value){
        SharedPreferences sharedPreferences = context.getSharedPreferences(mapKey, Context.MODE_PRIVATE);
        Editor sysEdit =  sharedPreferences.edit();
        sysEdit.putString(key, value);
        sysEdit.commit();
    }
    /**
     * 
     * [判断卡号是否为一帐通卡]<BR>
     * [true:是一帐通卡；false:不是一帐通卡]
     * @param accNo
     */
    public static boolean isToaPartyCard(String accNo)
    {
        String accNoHead = accNo.substring(0, 6);
        if("627069".equals(accNoHead)||"627068".equals(accNoHead)
                ||"627067".equals(accNoHead)
                ||"627066".equals(accNoHead)
                ||"621263".equals(accNoHead)
                ||"621261".equals(accNoHead))
        {
            return true;
        }
        else
        {
            return false;
        }
        
    }
    

    /**
     * [判断深发展卡类型]<BR>
     * [01:借记卡 02:信用卡 03:网银互联收款方]
     * 借记卡	622538,622535,622536,622539,622983,620010,412962,412963,998800
     * 信用卡	435744,435745,467192,467193,483536,622525,622526,998801,998802
     * 存折帐号	14位、10、11、12、18或19开头
     * @param card
     * @return
     */
    public static String isShenFaCardWithString(String card)
    {
    	String[] JiejiCards = new String[]{
    			"622538","622535","622536","622539","622983","620010","412962","412963","998800"
    	};
    	String[] XinyongCards = new String[]{
    			"435744","435745","467192","467193","483536","622525","622526","998801","998802"
    	};
    	
    	if(!Tools.isEmpty(card))
    	{
    		if(card.length() == 14 && (card.startsWith("10") || card.startsWith("11") || card.startsWith("12") || card.startsWith("18") || card.startsWith("19"))){
    			return "01";
    		}
    		
    		for(String c : JiejiCards){
    			if(card.startsWith(c)){
    				return "01";
    			}
    		}
    		
    		for(String c : XinyongCards){
    			if(card.startsWith(c)){
    				return "02";
    			}
    		}
    	}
    	
    	return null;
    }
    
    /**
     * [判断深发展卡存折类型]<BR>
     * 存折帐号	14位、10、11、12、18或19开头
     * @param card
     * @return
     */
    public static boolean isShenFaCunZheWithString(String card)
    {
    	if(!Tools.isEmpty(card))
    	{
    		if(card.length() == 14 && (card.startsWith("10") || card.startsWith("11") || card.startsWith("12") || card.startsWith("18") || card.startsWith("19"))){
    			return true;
    		}
    	}
    	
    	return false;
    }
    
    
    
    /**
     * [判断是否是一账通卡号]<BR>
     * [功能详细描述]
     * @param accNum
     * @return
     */
    public static boolean isCheckSuperCard(String accNum)
    {
    	    /* 借记卡	602907,622989,622986,622298
    	                  信用卡	622155,622156,622157,526855,531659,528020,356869
    	                  存折帐号	14位、10或12开头*/
    	
    	    boolean isYiZhangTong = false;
    	    if (!Tools.isEmpty(accNum) 
    	    		&& (accNum.indexOf("627069") > -1 
    	    		|| accNum.indexOf("627068") > -1 
    	    		|| accNum.indexOf("627067") > -1 
    	    		|| accNum.indexOf("627066") > -1 
    	    		|| accNum.indexOf("621263") > -1 
    	    		|| accNum.indexOf("621261")> -1 ))
    	    {
    	        isYiZhangTong = true;
    	    }

    	return isYiZhangTong;
    }
    
    /**
     * [判断是否是信用卡]<BR>
     * [功能详细描述]    信用卡	622155,622156,622157,526855,531659,528020,356869
     * @param account
     * @return
     */
    public static boolean isCheckXinYongCard(String account)
    {
    	 if(!Tools.isEmpty(account) 
    			 && (account.indexOf("622155") > -1  
        	     || account.indexOf("622156") > -1 
        	     || account.indexOf("622157") > -1 
        	     || account.indexOf("526855") > -1  
        	     || account.indexOf("531659") > -1 
        	     || account.indexOf("528020") > -1  
        	     || account.indexOf("356869") > -1 )){
    		 return true;
    	 }
    	return false;
    }
    
    /**
     * [得到头像]<BR>
     * [功能详细描述]
     * @param url
     * @return
     */
    public static int getHeadDrawable(String url)
    {
    	if(!Tools.isEmpty(url))
    	{
    		if(url.indexOf("00.png") > -1)
    		{
    			return R.drawable.sys_head_portrait_none;
    		}
    		if(url.indexOf("01.png") > -1){
    			return R.drawable.sys_head_portrait_01;
    		}
    		if(url.indexOf("02.png") > -1){
    			return R.drawable.sys_head_portrait_02;
    		}
    		if(url.indexOf("03.png") > -1){
    			return R.drawable.sys_head_portrait_03;
    		}
    		if(url.indexOf("04.png") > -1){
    			return R.drawable.sys_head_portrait_04;
    		}
    		if(url.indexOf("05.png") > -1){
    			return R.drawable.sys_head_portrait_05;
    		}
    		if(url.indexOf("06.png") > -1){
    			return R.drawable.sys_head_portrait_06;
    		}
    		if(url.indexOf("07.png") > -1){
    			return R.drawable.sys_head_portrait_07;
    		}
    		if(url.indexOf("08.png") > -1){
    			return R.drawable.sys_head_portrait_08;
    		}
    		if(url.indexOf("09.png") > -1){
    			return R.drawable.sys_head_portrait_09;
    		}
    		if(url.indexOf("10.png") > -1){
    			return R.drawable.sys_head_portrait_10;
    		}
    		if(url.indexOf("11.png") > -1){
    			return R.drawable.sys_head_portrait_11;
    		}
    		if(url.indexOf("12.png") > -1){
    			return R.drawable.sys_head_portrait_12;
    		}
    		if(url.indexOf("13.png") > -1){
    			return R.drawable.sys_head_portrait_13;
    		}
    		if(url.indexOf("14.png") > -1){
    			return R.drawable.sys_head_portrait_14;
    		}
    		if(url.indexOf("15.png") > -1){
    			return R.drawable.sys_head_portrait_15;
    		}
    		if(url.indexOf("16.png") > -1){
    			return R.drawable.sys_head_portrait_16;
    		}
    	}
    	return R.drawable.sys_head_portrait_none;
    }
	
    
    /**
     * 本地头像资源 assets/images/addModify/01.png

     */
    public static String[] sys_head_images_url = 
    { 
        "assets/images/addModify/00.png",
		"assets/images/addModify/01.png", "assets/images/addModify/02.png",
		"assets/images/addModify/03.png", "assets/images/addModify/04.png",
		"assets/images/addModify/05.png", "assets/images/addModify/06.png",
		"assets/images/addModify/07.png", "assets/images/addModify/08.png",
		"assets/images/addModify/09.png", "assets/images/addModify/10.png",
		"assets/images/addModify/11.png", "assets/images/addModify/12.png",
		"assets/images/addModify/13.png", "assets/images/addModify/14.png",
		"assets/images/addModify/15.png", "assets/images/addModify/16.png"
	};
    
    /**
     * 本地头像资源
     */
    public static int[] sys_head_images = 
    { 
        R.drawable.sys_head_portrait_user_define,
		R.drawable.sys_head_portrait_01, R.drawable.sys_head_portrait_02,
		R.drawable.sys_head_portrait_03, R.drawable.sys_head_portrait_04,
		R.drawable.sys_head_portrait_05, R.drawable.sys_head_portrait_06,
		R.drawable.sys_head_portrait_07, R.drawable.sys_head_portrait_08,
		R.drawable.sys_head_portrait_09, R.drawable.sys_head_portrait_10,
		R.drawable.sys_head_portrait_11, R.drawable.sys_head_portrait_12,
		R.drawable.sys_head_portrait_13, R.drawable.sys_head_portrait_14,
		R.drawable.sys_head_portrait_15, R.drawable.sys_head_portrait_16 
	};
    
    /**
	 * [格式化账号]<BR>
	 * [功能详细描述]
	 * @param alias 别名
	 * @param accnum 账号
	 * @return
	 */
	public static String formatAccount(String alias, String accnum ,int totallen)
	{
		if(Tools.isEmpty(accnum)) {
			return "";
		}
		
		StringBuilder curAccountStr = new StringBuilder();
		String malias = CommonUtils.getAlias(String.valueOf(alias));
		int strlen = Tools.getLength(malias);
		
		if(strlen < totallen){
			int len = totallen - strlen;
			for(int i= 0;i<len ;i++){
				malias += " ";
			}
		}
		malias = Tools.splitString(malias, totallen);
		
		curAccountStr.append(malias);
		curAccountStr.append(":");
		curAccountStr.append(Tools.dealTheCradNum(String.valueOf(accnum)));
		return curAccountStr.toString();
	}
	
	/************************模拟堆栈，管理Activity************************/	
	
	public static void remove(Activity activity){
		activityList.remove(activity);
	}
	
	public static void add(Activity activity){
		activityList.add(activity);
	}
	
	public static void finishProgram(){
		for(Activity activity:activityList){
			activity.finish();
		}
//		WebTrends.exitTrack();
		android.os.Process.killProcess(android.os.Process.myPid());
	}
	
	/**
	 * [通过汇率得到折算成人名币]<BR>
	 * @param balance 货币
	 * @param rate 汇率
	 */
	public static float getBalanceToRMB(float balance, float rate) {
		return 10000 * balance / rate;
	}
	
	/**
	 * [通过汇率得到折算成人名币,用于处理大数]<BR>
	 * @param balance 货币
	 * @param rate 汇率
	 */
	public static BigDecimal getBalanceToRMB(String value, String rate) {
		
		BigDecimal valueDecimal = new BigDecimal(value);
		BigDecimal rateDecimal = new BigDecimal(rate);
		return getBalanceToRMB(valueDecimal, rateDecimal);
	}
	
	public static BigDecimal getBalanceToRMB(BigDecimal valueDecimal, BigDecimal rateDecimal) {
		
		BigDecimal mulDecimal = new BigDecimal(10000);
		BigDecimal mulResult = valueDecimal.multiply(mulDecimal);
		BigDecimal result = mulResult.divide(rateDecimal, 2, BigDecimal.ROUND_HALF_UP);
		return result;
	}
	
	/**
	 * [大数比较]<BR>
	 * @param value1
	 * @param value2
	 * @return 1为大于，-1为小于，0为等于
	 */
	public static int compareBigNum(String value1, String value2) {
		BigDecimal bigDecimal = new BigDecimal(value1);
		BigDecimal bigDecimal2 = new BigDecimal(value2);
		return bigDecimal.compareTo(bigDecimal2);
	}
	
	/**
	 * [两个日期的对比]<BR>
	 * [功能详细描述]
	 * @param dateStr1
	 * @param dateStr2
	 * @return 大于为1,小于为-1,等于为0,非法为-2
	 */
	public static int compareDate(String dateStr1, String dateStr2) {
		
		if(dateStr1 == null || dateStr1.equals("")) {
			return -2;
		}
		if(dateStr2 == null || dateStr2.equals("")) {
			return -2;
		}
		
		try {
			Date date1 = dateFormat.parse(dateStr1);
			Date date2 = dateFormat.parse(dateStr2);
			return date1.compareTo(date2);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return -2;
	}
	
	/**
	 * [两个日期的对比]<BR>
	 * [功能详细描述]
	 * @param dateStr1
	 * @param dateStr2
	 * @param format
	 * @return 大于为1,小于为-1,等于为0,非法为-2
	 */
	public static int compareDate(String dateStr1, String dateStr2, String format) {
		SimpleDateFormat asf = new SimpleDateFormat(format);
		if(dateStr1 == null || dateStr1.equals("")) {
			return -2;
		}
		if(dateStr2 == null || dateStr2.equals("")) {
			return -2;
		}
		
		try {
			Date date1 = asf.parse(dateStr1);
			Date date2 = asf.parse(dateStr2);
			return date1.compareTo(date2);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return -2;
	}
	
	/**
	 * [显示交易限额限制Dialog]<BR>
	 * @param data
	 */
	public static void showQuotaErrorDialog(final Context context, String msg) {
		
		CommonUtils.setOnAlertDialogLeftButtonClickListener(new OnAlertDialogButtonClickListener(){
			@Override
			public void onClick() {
//				context.startActivity(new Intent(context, DealLimitationSummary.class));
			}
		});
		CommonUtils.setOnAlertDialogRightButtonClickListener(null);
		CommonUtils.showAlertDialog(context, 
				msg,
				"修改限额",
				"取消");
	}
	
	/**
	 * [得到Map中的第一个Key]<BR>
	 * @param map map
	 * @return key值
	 */
	public static Object getMapKey(Map map) {
		
		Iterator it = map.keySet().iterator();
		if (it.hasNext()) {
			return it.next();
		}
		return null;
	}
	
	/**
	 * 数字转换为中文大写
	 * 
	 * @param currencyDigits
	 * @return
	 */
	public static String convertMoney(String currencyDigits) {

		String CN_ZERO = "零";
		String CN_DOLLAR = "圆";
		String[] digits = new String[] { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
		String[] radices = new String[] { "", "拾", "佰", "仟" };
		String[] bigRadices = new String[] { "", "万", "亿", "万" };
		String[] decimals = new String[] { "角", "分" };
		
		String integral = null; // 整数部分
		String decimal = null; // 小数部分
		String outputCharacters = null; // 最终转换输出结果

		String d = null;
		int zeroCount = 0, p = 0, quotient = 0, modulus = 0;

		// 删除数字中的逗号,
		currencyDigits = currencyDigits.replace("/,/g", "");
		// 删除数字左边的0
		currencyDigits = currencyDigits.replace("/^0+/", "");

		// 拆分数字中的整数与小数部分
		String[] parts = currencyDigits.split("\\.");
		if (parts.length > 1) {
			integral = parts[0];
			decimal = parts[1];

			// 如果小数部分长度大于2，四舍五入，保留两位小数
			if (decimal.length() > 2) {
				long dd = Math.round(Double.parseDouble("0."+decimal) * 100) ;
				decimal = Long.toString(dd);
			}

		} else {
			integral = parts[0];
			decimal = "0";
		}

		outputCharacters = "";
		if (Double.parseDouble(integral) > 0) {

			zeroCount = 0;

			for (int i = 0; i < integral.length(); i++) {

				p = integral.length() - i - 1;
				d = integral.substring(i, i + 1);

				quotient = p / 4;
				modulus = p % 4;
				if (d.equals("0")) {
					zeroCount++;
				} else {
					if (zeroCount > 0) {
						outputCharacters += digits[0];
					}
					zeroCount = 0;
					outputCharacters += digits[Integer.parseInt(d)] + radices[modulus];
				}
				if (modulus == 0 && zeroCount < 4) {
					outputCharacters += bigRadices[quotient];
				}
			}
			outputCharacters += CN_DOLLAR;
		}

		if (Double.parseDouble(decimal) > 0) {
			for (int i = 0; i < decimal.length(); i++) {
				d = decimal.substring(i, i + 1);
				if (!d.equals("0")) {
					outputCharacters += digits[Integer.parseInt(d)] + decimals[i];
				} else {
					if (i == 0) {
						outputCharacters += CN_ZERO;
					}
				}
			}
		}
		
		if (outputCharacters.equals("")) {
			outputCharacters = CN_ZERO + CN_DOLLAR;
		}

		return outputCharacters;
	}
	
	/**
	 * [获取当前日期]<BR>
	 * 格式：20111225
	 * 优先取服务器时间，如果服务器时间为空则取当前时间
	 * @return
	 */
	public static String getCurrentTime() {
		
		return getCurrentTime("yyyyMMdd");
	}
	
	/**
	 * [format若为空，则直接返回long值]<BR>
	 * @param format
	 * @return
	 */
	public static String getCurrentTime(String format) {
		String currentTime = "";
		
		Map<String, Object> map = DataCache.getCache(R.string.QUERY_EBANK_SYSTIME, 0);
		if (map != null) {
			 Map<String, Object> sysTimeMap = (Map<String, Object>)map.get(AppKeyConstants.RESPONSE_BODY);
			 Object sysTime = sysTimeMap.get(AppKeyConstants.SYS_TIME);
			 if (sysTime != null) {
				 String curTime = sysTime.toString();
				 long timeLong = Long.parseLong(curTime);
				 if (format != null) {
					 currentTime = Tools.LongToFormatDate(timeLong, format);
				 } else {
					 currentTime = timeLong + "";
				 }
			 }
		} else {
			currentTime = getToday(format);
		}
		
		return currentTime;
	}
	
	 /**
     * [获取当前日期]<BR>
     * 优先取服务器时间，如果服务器时间为空则取当前时间
     * @return 代表当前日期的Calendar对象
     */
	public static Calendar getCurrentTimeByCalendar() {
	    String currentDateStr = getCurrentTime();
	    
	    String year = currentDateStr.substring(0, 4);
	    String month = currentDateStr.substring(4, 6);
	    String day = currentDateStr.substring(6);
	    
	    Calendar currentTime = Calendar.getInstance();
	    
	    currentTime.clear();
	    currentTime.set(Calendar.YEAR, Integer.parseInt(year));
	    currentTime.set(Calendar.MONTH, Integer.parseInt(month) - 1);
	    currentTime.set(Calendar.DAY_OF_MONTH, Integer.parseInt(day));
	    
	    return currentTime;
	}
	
	/**
     * [获取当前日期]<BR>
     * 优先取服务器时间，如果服务器时间为空则取当前时间
     * @return 代表当前日期的Calendar对象
     */
	public static Calendar getCurrentTimeByCalendarAmpm() {
	    String currentDateStr = getCurrentTime("yyyyMMddHH");
	    
	    String year = currentDateStr.substring(0, 4);
	    String month = currentDateStr.substring(4, 6);
	    String day = currentDateStr.substring(6,8);
	    String ampm = currentDateStr.substring(8,10);
	    
	    Calendar currentTime = Calendar.getInstance();
	    
	    currentTime.clear();
	    currentTime.set(Calendar.YEAR, Integer.parseInt(year));
	    currentTime.set(Calendar.MONTH, Integer.parseInt(month) - 1);
	    currentTime.set(Calendar.DAY_OF_MONTH, Integer.parseInt(day));
	    currentTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(ampm));
	    
	    
	    return currentTime;
	}
	
	
	public static String getNoticeType(String term, String endDate) {
		if (term.equals("7")) {
			if (endDate == null || endDate.equals("")) {
				term = "七天通知";
			} else {
				term = "智能七天通知";
			}
		} if (term.equals("1")) {
			term = "一天通知";
		}
		return term;
	}
	
	public static String getOrderType(String value) {
		if (value.equals("00")) {
			return "行内活期转账";
		} else if (value.equals("01")) {
			return "活期转定期";
		} else if (value.equals("07")) {
			return "跨行转账";
		} else if (value.equals("14")) {
			return "信用卡还";
		}
		return "未知";
	}
	/**
	 * 是否需要帮助向导
	 * @param context context
	 * @return true为需要
	 */
	public static boolean isNeedHelper(Context context){
		SharedPreferences preference = context.getSharedPreferences(SHARED_CONFIG_FILE_NAME, Context.MODE_PRIVATE);
		//已经 被帮助过的版本号
		int helperVersion = preference.getInt(AppKeyConstants.SHARED_APP_VERSION_FOR_HELPER, AppKeyConstants.SHARED_INITEGER_DEFAULT);
		//当前版本号
		int curVersion = getAppVersionCode(context);
		if(curVersion!=helperVersion){
			return true;
		}
		return false;
		
	}
	/**
	 * 检查是否需要导航
	 * @param context	context
	 * @param navType	
	 * {@link AppKeyConstants#SHARED_HOME_FIRST_LAUNCHER}  
	 * {@link AppKeyConstants#SHARED_CALANDER_FIRST_LAUNCHER}
	 * {@link AppKeyConstants#SHARED_TRANSFER_FIRST_LAUNCHER}  
	 * {@link AppKeyConstants#SHARED_MY_SELF_FIRST_LAUNCHER}
	 * @return 如果需要导航会返回true
	 */
	public static boolean isNeedNavigation(Context context,String navType){
		SharedPreferences preference = context.getSharedPreferences(SHARED_CONFIG_FILE_NAME, Context.MODE_PRIVATE);
		return preference.getBoolean(navType, true);
	}
	/**
	 * 用户不再需要导航
	 * @param context	context
	 * @param navType	
	 * {@link AppKeyConstants#SHARED_HOME_FIRST_LAUNCHER}  
	 * {@link AppKeyConstants#SHARED_CALANDER_FIRST_LAUNCHER}
	 * {@link AppKeyConstants#SHARED_TRANSFER_FIRST_LAUNCHER}  
	 * {@link AppKeyConstants#SHARED_MY_SELF_FIRST_LAUNCHER}
	 */
	public static void cancleNavigation(Context context,String navType){
		SharedPreferences preference = context.getSharedPreferences(SHARED_CONFIG_FILE_NAME, Context.MODE_PRIVATE);
		Editor mSharedDataEditor = preference.edit();
		mSharedDataEditor.putBoolean(navType, false);
		mSharedDataEditor.commit();
	}
	
	/**
	 * 记录帮助  代表这个版本我已经被帮助向导过一次
	 * @param version 要记录的版本号
	 */
	public static void recordHelper(int version,Context context){
		SharedPreferences preference = context.getSharedPreferences(SHARED_CONFIG_FILE_NAME, Context.MODE_PRIVATE);
		Editor mSharedDataEditor = preference.edit();
		mSharedDataEditor.putInt(AppKeyConstants.SHARED_APP_VERSION_FOR_HELPER, version);
		mSharedDataEditor.commit();
	}
	/**
	 * 记录帮助  代表当前这个应用版本我已经帮助过
	 */
	public static void recordHelper(Context context){
		recordHelper(getAppVersionCode(context), context);
	}
	
	/**
	 * 返回当前程序版本名
	 */
	public static int getAppVersionCode(Context context) {
		int versioncode = 0;
		try {
			// ---get the package info---
			PackageManager pm = context.getPackageManager();
			PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
			versioncode = pi.versionCode;
			
		} catch (Exception e) {
			Log.e("VersionInfo", "Exception", e);
		}
		return versioncode;
	}
	
	/**
	 * 返回当前程序版本名
	 */
	public static String getAppVersionName(Context context) {
		String versionName = "";
		try {
			// ---get the package info---
			PackageManager pm = context.getPackageManager();
			PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
			versionName = pi.versionName;
			if (versionName == null || versionName.length() <= 0) {
				return "";
			}
		} catch (Exception e) {
			Log.e("VersionInfo", "Exception", e);
		}
		return versionName;
	}
	
	/**
	 * [得到卡号日期更大的卡]<BR>
	 * @param num1
	 * @param num2
	 * @return
	 */
	public static String getBigNumCard(String num1, String num2) {
		
		int a1 = Integer.parseInt(num1.substring(0, 8));
		int a2 = Integer.parseInt(num2.substring(0, 8));
		
		if (a1 > a2) {
			return num1;
		}
		
		return num2;
	}
	
	/**
	 * [得到下载全路径，适配各个环境]<BR>
	 * [功能详细描述]
	 * @return
	 */
	public static String getDownLoadUrl(String url)
	{	
		StringBuilder downurl = new StringBuilder();
		
		if(url.indexOf("http") > -1){
			return url;
		}
		else{
			if(Constants.CURRENT_HOST == R.string.PRODUCT_ADDRESS){
				downurl.append(HttpHelper.getUrlById(R.string.IMAGE_URL)).append(url);
			}
			else{
				downurl.append(HttpHelper.getUrlById(R.string.IMAGE_URL_STG)).append(url);
			}
		}
		
		return downurl.toString();
	}
	
	/**
	 * [一句话功能简述]<BR>
	 * [功能详细描述]
	 * @param context
	 * @param len
	 * @return
	 */
	public static String getVersionName(Context context, int len)
	{
	    String versionName = "";
		PackageInfo pinfo = null;
		
		try {
			pinfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_CONFIGURATIONS);
			versionName = pinfo.versionName;
			if(!Tools.isEmpty(versionName) && len > 0){
				if(versionName.length() >= len){
					versionName = versionName.substring(0, len);
				}
			}
		 } catch (NameNotFoundException e) {
			e.printStackTrace();
		 }
		
		 APPLog.e(TAG, "getVersionName : " + versionName);
		 return versionName;
	 }
	
	 /**
	 * [一句话功能简述]<BR>
	 * [功能详细描述]
	 * @param context
	 * @return
	 */
	public static String getVersionName(Context context)
	{
		 return getVersionName(context , 3);
	 }
	
	public static List<Map<String, Object>> sort(List<Map<String, Object>> dataList, String sortByKey) {
		
		int tempLength;
		int length = dataList.size();
		String no1;
		String no2;
		Map<String, Object> map1;
		Map<String, Object> map2;
		Map<String, Object> tempMap;
		for (int i = 0;i < length;i++) {
			tempLength = length - i - 1;
			for (int j = 0;j < tempLength;j++) {
				map1 = dataList.get(j);
				map2 = dataList.get(j + 1);
				no1 = map1.get(sortByKey).toString();
				no2 = map2.get(sortByKey).toString();
				if (no1 != null && ! no1.equals("") && no2 != null && !no2.equals("")) {
					int num1 =Integer.parseInt(no1);
					int num2 =Integer.parseInt(no2);
					if (num1 < num2) {
						tempMap = map1;
						dataList.set(j, map2);
						dataList.set(j + 1, map1);
						tempMap = null;
					}
				}
			}
		}
		return dataList;
	}
	
	/**
	 * [检查转账账号列表中是否存在相同的账号]<BR>
	 * [功能详细描述]
	 * @return
	 */
	public static boolean checkTransferSameAcc(String curAcc)
	{
//		if(PageCache.TRANSFER_PAYEE_LIST != null && !PageCache.TRANSFER_PAYEE_LIST.isEmpty()){
//			for(Map<String, String> curmap : PageCache.TRANSFER_PAYEE_LIST){
//				if(curAcc.equals(curmap.get(KeyConstants.ACCOUNT_NUMBER))){
//					return false;
//				}
//			}
//		}
		return true;
	}
	
	/**
	 * 
	 * [判断是否为高级网银用户]<BR>
	 * [功能详细描述]
	 * 用户类别：0-普通 1-高级
	 * @return
	 */
	public static boolean isHighGradeUser(){
		DataHashMap<String, Object> map = (DataHashMap<String, Object>) DataCache.getCache(R.string.BANK_QUERYUSERINFO, 0);
		if(map != null){
			String userType = map.getStringBykey("Data/responseBody/userType");
			return "1".equals(userType) ? true : false;
		}
		return false;
	}
   

	/**
	 * 
	 * [判断当前应用是否处于生产环境]<BR>
	 * [功能详细描述]
	 * @return
	 */
	public static boolean isInEnvironmentOfProduct(){
		return R.string.PRODUCT_ADDRESS == Constants.CURRENT_HOST ? true : false ;
	}
	/**
	 * 获取贷款还款方式
	 * @param repayTypeKey 还款方式 key<br>
	 *  值	   含义
	    1	按月等额还款    
	    2	按月等本还款    
	    3	利随本清        
	    4	净息还款        
	    5	等额递增还款法  
	    6	等比递增还款法  
	    7	快速双周供(等额)
	    8	快速双周供(等本)
	    10	按季结息一次还清  
	    11	自定义还款        
	    15	低供贷            
	    16	尾款还款          
	    17	宽限期不还款法    
	    18	宽限期还息法      
	    19	宽限期固定还款额法
	    151	低供贷(按月等额)
	    152	低供贷(按月等本)
	    157	低供贷(双周等额)
	    158	低供贷(双周等本)
	 * @return 还款方式values
	 */
	public static String getLoanRepayType(String repayTypeKey) {
		if ("1".equals(repayTypeKey)) {
			return "按月等额还款";
		} else if ("2".equals(repayTypeKey)) {
			return "按月等本还款";
		} else if ("3".equals(repayTypeKey)) {
			return "利随本清";
		} else if ("4".equals(repayTypeKey)) {
			return "净息还款";
		} else if ("5".equals(repayTypeKey)) {
			return "等额递增还款法";
		} else if ("6".equals(repayTypeKey)) {
			return "等比递增还款法";
		} else if ("7".equals(repayTypeKey)) {
			return "快速双周供(等额)";
		} else if ("8".equals(repayTypeKey)) {
			return "快速双周供(等本)";
		} else if ("10".equals(repayTypeKey)) {
			return "按季结息一次还清";
		} else if ("11".equals(repayTypeKey)) {
			return "自定义还款";
		} else if ("15".equals(repayTypeKey)) {
			return "低供贷";
		} else if ("16".equals(repayTypeKey)) {
			return "尾款还款";
		} else if ("17".equals(repayTypeKey)) {
			return "宽限期不还款法";
		} else if ("18".equals(repayTypeKey)) {
			return "宽限期还息法";
		} else if ("19".equals(repayTypeKey)) {
			return "宽限期固定还款额法";
		} else if ("151".equals(repayTypeKey)) {
			return "低供贷(按月等额)";
		} else if ("152".equals(repayTypeKey)) {
			return "低供贷(按月等本)";
		} else if ("157".equals(repayTypeKey)) {
			return "低供贷(双周等额)";
		} else if ("158".equals(repayTypeKey)) {
			return "低供贷(双周等本)";
		}
		return "";
	}

	/**
	 * [得到ChannelType跟时间搓]<BR>
	 * [功能详细描述]
	 * @return
	 */
	public static String getChanneltypeWithTime()
	{
		StringBuilder time = new StringBuilder();
		SimpleDateFormat mFormatter = new SimpleDateFormat("yyyyMMddHHmmss");
		Date currentDate = new Date(System.currentTimeMillis());

//		time.append(HttpHelper.CHANNELTYPE_VALUE);
		time.append("#");
		time.append(mFormatter.format(currentDate));
		
		return time.toString();
	}
	/**
	 * 获取定投周期
	 * @param peroid
	 * @return
	 */
	public static String getPurchasePeroid(String peroid){
		if("0".equals(peroid)){
			return "每月";
		}else if("1".equals(peroid)){
			return "每周";
		}else if("2".equals(peroid)){
			return "每日";
		}
		return "";
	}
	
	/**
	 * 排序
	 * @param list list
	 * @param key key
	 */
	public static void sortList(List<Map<String, Object>> list, final String key) {
		Comparator<Map<String, Object>> mapComprator = new Comparator<Map<String, Object>>() {

			@Override
			public int compare(Map<String, Object> o1, Map<String, Object> o2) {
				String date1 = (String) o1.get(key);
				String date2 = (String) o2.get(key);
				int compare = compareDate(date1, date2);
				if (date1.equals("") && date2.equals("")) {
					return 0;
				}
				if (date1.equals("")) {
					return 1;
				}
				if (date2.equals("")) {
					return -1;
				}
				if (compare == -1) {
					return 1;
				} else if (compare == 1) {
					return -1;
				} else {
					return 0;
				}
			}
		};

		Collections.sort(list, mapComprator);
	}
	
	/**
	 * 判断该贷款是否可提前还款
	 * @param businessType 贷款类型
	 * @return
	 */
	public static boolean isPrePaymentEnable(String businessType){
		
		if ("1140030".equals(businessType)) {
			//员工信用贷款
			return true;
		} else if ("1110010".equals(businessType)){
			//员工住房贷款
			return true;
		} else if ("1150070".equals(businessType)){
			//赎楼贷款
			return true;
		} else if ("1150020".equals(businessType)){
			//国家助学贷款
			return true;
		} else if ("1190010".equals(businessType)){
			//个人委托贷款
			return true;
		} else if ("1190020".equals(businessType)){
			//住房公积金贷款
			return true;
		} else if ("1160010".equals(businessType)){
			//房屋持证抵押授信额度
			return true;
		}
		
		//不可提前还款
		return false;
	}
	
	/**
	 * 判断是否有SD卡
	 * @return
	 */
	public static boolean avaiableSDCard(){  
		
        String status = Environment.getExternalStorageState();  
          
        if(status.equals(Environment.MEDIA_MOUNTED)){  
            return true;  
        }  
        else {  
            return false;  
        }  
    }
	
	
}
